package org.crc.myvhrb.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

/**
 * CRC
 * 2021/8/20
 */
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    // 注册端点、连接点
    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        // 配置连接点
        registry.addEndpoint("/ws/ep")
                // 允许连接的域
                .setAllowedOrigins("http://localhost:8080")
                // 开启 withSockJS
                .withSockJS();
    }

    // 消息代理
    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        registry.enableSimpleBroker("/queue");
    }
}
